package com.coocaa.ops.admin.v1.upload;

import com.coocaa.ops.admin.base.controller.MgrBaseController;
import com.coocaa.ops.admin.v1.upload.model.UploadConfig;
import com.coocaa.ops.admin.v1.upload.service.IUploadService;
import com.coocaa.ops.admin.v1.upload.util.UploadConfigValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author tangminghong
 * @date 2020-06-18
 */
@RestController
@RequestMapping(value = "/v1/upload", method = RequestMethod.POST)
public class UploadController extends MgrBaseController {


    @Autowired
    private IUploadService uploadService;

    /**
     * 上传图片
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/image", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
    public Object uploadImage(HttpServletRequest request) {
        Map result = uploadService.uploadImage(request);
        return render2Json(result);
    }

    /**
     * 上传zip
     *
     * @param request
     * @param
     * @return
     */
    @RequestMapping(value = "/zip",  method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
    public Object uploadZip(HttpServletRequest request, UploadConfig uploadConfig) {
        UploadConfigValidator.valid(uploadConfig);
        Map result = uploadService.uploadZip(request, uploadConfig);
        return render2Json(result);
    }

    /**
     * 上传APK
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/apk", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
    public Object uploadApk(HttpServletRequest request) {
        Map result = uploadService.uploadApk(request);
        return render2Json(result);
    }
}
